package com.xjcs.saplingplan.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.xjcs.saplingplan.databinding.ItemCountdownTypeBinding
import com.xjcs.saplingplan.model.bean.countdown.CountdownTypeBean

class CountdownTypeAdapter(
    private val context: Context,
    private val dataList: MutableList<CountdownTypeBean>
) : RecyclerView.Adapter<CountdownTypeAdapter.ItemCountdownTypeViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemCountdownTypeViewHolder {
        val binding =
            ItemCountdownTypeBinding.inflate(LayoutInflater.from(context), parent, false)
        return ItemCountdownTypeViewHolder(binding)
    }

    override fun getItemCount(): Int = dataList.size

    override fun onBindViewHolder(holder: ItemCountdownTypeViewHolder, position: Int) {
        val item = dataList.getOrNull(position)
        holder.bind(item)
    }

    class ItemCountdownTypeViewHolder(
        private val binding: ItemCountdownTypeBinding
    ) :
        RecyclerView.ViewHolder(binding.root) {
        fun bind(item: CountdownTypeBean?){
            item?.let {
                binding.tvType.text = it.name
            }
        }
    }

}